<template>
	<view class="my-list">
		<!-- 顶部 -->
		<view class="my-header">
			<image class="head-photo" :src="userInfo.imgUrl" mode="" @tap="EditUser"></image>
			<view class="head-info">
				<text>{{ loginStatus ? userInfo.nickName : "用户名称"   }}</text>
				<view class="phone">
					<image class="phone-img" src="../../static/image/my/phone.png" mode=""></image>
					<text class="phone-number">{{ loginStatus ? userInfo.phone :'***********' }}</text>
				</view>
			</view>
		</view>
		<!-- 订单状态部分 -->
		<view class="order-status">
			<view v-for="(item,index) in orderStatusData" :key="index">
				<view class="orderStatue-item" @tap="goOrder(item,index)">
					<image class="statusImage" :src="item.Image" mode=""></image>
					<text>{{item.name}}</text>
				</view>
			</view>
		</view>

		<!-- 中间菜单部分 -->
		<view class="bodyMenue">
			<view v-for="(item,index) in bottomDataList" :key="index" @tap="ClickMenue(item,index)">
				<view class="menueItem">
					<view class="menueItemLeft">
						<image class="left-image" :src="item.leftImage" mode=""></image>
						<text class="text">{{item.name}}</text>
					</view>
					<view class="menueItemRight">
						<image class="arror-right" :src="item.rightImage" mode=""></image>
					</view>
				</view>
			</view>
		</view>
		<Tabbar cureentPage="my"></Tabbar>
	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex';
	import Tabbar from '../../components/common/TabBar.vue'
	import $http from "../../common/api/request.js"
	export default {
		data() {
			return {
				// 订单状态 图片数据
				orderStatusData: [],
				// 我的  列表
				bottomDataList: []
			}
		},
		computed: {
			...mapState({
				loginStatus: state => state.user.loginStatus,
				userInfo: state => state.user.userInfo
			})
		},
		components: {
			Tabbar
		},
		onLoad() {
			this.getOrderStatusData()
			this.getList()
			let _this = this
			uni.$on('updateAll', function(data) {
				_this.ClickMenue(0)
			})
		},
		methods: {
			// 编辑用户资料
			EditUser() {
				uni.navigateTo({
					url: '/pages/login-set-pwd/login-set-pwd?pageType=' + 'my' + ''
				})
			},
			getOrderStatusData() {
				$http.request({
					url: '/my/orderStatusList',
					method: 'GET',
				}).then((res) => {
					this.orderStatusData = res.orderStatusData
				}).catch(() => {
					uni.showToast({
						title: "请求失败",
						icon: "none"
					})
				})
			},
			getList() {
				$http.request({
					url: '/my/myList',
					method: 'GET',
				}).then((res) => {
					this.bottomDataList = res.bottomDataList
				}).catch(() => {
					uni.showToast({
						title: "请求失败",
						icon: "none"
					})
				})
			},
			ClickMenue(item, index) {
				// 如果点击事件的索引值为2 跳转到地址管理页面
				if (index == 2) {
					uni.navigateTo({
						url: '/pages/path-list/path-list'
					})
				} else if (index == 0) {
					// 如果索引值为0 跳转全部订单页面
					let id = 0
					uni.navigateTo({
						url: "/pages/order-all/order-all?id=" + id + ""
					})
				} else if (index == 3) {
					//
					uni.navigateTo({
						url: "/pages/goods_browse/goods_browse"
					})
				} else if (index == 1) {
					uni.navigateTo({
						url: "/pages/my-collect/my-collect"
					})
				} else if (index == 4) {
					uni.navigateTo({
						url: '/pages/my-store-list/my-store-list',
					})
				}

			},
			// 点击跳转到订单页面 ，并且指定跳转状态
			goOrder(item, index) {
				let id = index + 1
				uni.navigateTo({
					url: '/pages/order-all/order-all?id=' + id + ''
				})
			}
		},
		// 顶部原生导航栏按钮点击事件
		onNavigationBarButtonTap(e) {
			// 点击设置，跳转到设置页面
			if (e.float == "left") {
				uni.navigateTo({
					url: '/pages/my-config/my-config'
				})
			}
		}
	}
</script>

<style scoped>
	.my-list {
		width: 100%;
		height: 100%;
		background-color: #efefef;
	}

	.my-header {
		width: 100%;
		height: 300rpx;
		background-color: #f6571d;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.head-photo {
		width: 100rpx;
		height: 100rpx;
		border-radius: 100%;
		margin-left: -350rpx;
	}

	.head-info {
		display: flex;
		flex-direction: column;
		margin-left: 10rpx;
		padding-left: 20rpx;
		color: white;
	}

	.phone {
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.phone-img {
		width: 30rpx;
		height: 30rpx;
	}

	.order-status {
		width: 100%;
		height: 140rpx;
		display: flex;
		justify-content: space-around;
		align-items: center;
		background-color: white;
	}

	.orderStatue-item {
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
	}

	.statusImage {
		width: 60rpx;
		height: 60rpx;
	}

	.bodyMenue {
		margin-top: 50rpx;
	}

	.menueItem {
		width: 710rpx;
		display: flex;
		padding: 10rpx 20rpx;
		justify-content: space-between;
		align-items: center;
		border-bottom: 2rpx solid #e1e1e1;
		background-color: white;
	}

	.menueItemLeft {
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.left-image {
		width: 30rpx;
		height: 30rpx;
	}

	.arror-right {
		width: 30rpx;
		height: 30rpx;
	}

	.text {
		margin-left: 10rpx;
		font-size: 24rpx;
	}
</style>